﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Business.Models;
using System.Data;

namespace Business.DAO
{
    public class LopHocDAO
    {
        private ISSContext db = new ISSContext();
        public List<LopHoc> GetAll()
        {
            return db.LopHoc.ToList();
        }

        public LopHoc Get(int id)
        {
            LopHoc LopHoc = db.LopHoc.Find(id);
            return LopHoc;
        }

        public int Create(LopHoc LopHoc)
        {
            try
            {
                db.LopHoc.Add(LopHoc);
                return db.SaveChanges();
            }
            catch (Exception ex)
            {
                return 0;
            }
        }

        public int Edit(LopHoc LopHoc)
        {
            try
            {
                db.Entry(LopHoc).State = EntityState.Modified;
                return db.SaveChanges();
            }
            catch (Exception ex)
            {
                return 0;
            }
        }

        public int Delete(int id)
        {
            try
            {
                LopHoc LopHoc = db.LopHoc.Find(id);
                db.LopHoc.Remove(LopHoc);
                return db.SaveChanges();
            }
            catch (Exception ex)
            {
                return 0;
            }
        }

        public List<LopHoc> GetByNienHoc(int IdNienHoc)
        {
            var query = from lophoc in db.LopHoc where lophoc.IdNienHoc == IdNienHoc select lophoc;
            List<LopHoc> lstLopHoc = query.ToList<LopHoc>();
            return lstLopHoc;
        }

        public List<LopHoc> GetByKhoiLop(KhoiLop KhoiLop)
        {
            var query = from lophoc in db.LopHoc where lophoc.KhoiLop == KhoiLop select lophoc;
            List<LopHoc> lstLopHoc = query.ToList<LopHoc>();
            return lstLopHoc;
        }

        public List<LopHoc> GetByQuanTri(QuanTri QuanTri)
        {
            var query = from lophoc in db.LopHoc where lophoc.QuanTri == QuanTri select lophoc;
            List<LopHoc> lstLopHoc = query.ToList<LopHoc>();
            return lstLopHoc;
        }

        public List<LopHoc> GetByKhoiLop_NienHoc(KhoiLop KhoiLop, NienHoc NienHoc)
        {
            var query = from lophoc in db.LopHoc where lophoc.NienHoc == NienHoc && lophoc.KhoiLop == KhoiLop select lophoc;
            List<LopHoc> lstLopHoc = query.ToList<LopHoc>();
            return lstLopHoc;
        }
    }
}